import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kasax_demos2/day16_getx/sample_demo_getx_controller_pagetwo.dart';

/// 跨界面交互
class SampleDemoGetXController extends StatefulWidget {
  const SampleDemoGetXController({Key? key}) : super(key: key);

  @override
  _SampleDemoGetXControllerState createState() =>
      _SampleDemoGetXControllerState();
}

class _SampleDemoGetXControllerState extends State<SampleDemoGetXController> {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      home: PageOne(),
    );
  }
}

class PageOne extends StatelessWidget {
  const PageOne({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final oneController = Get.put(PageOneController());
    return Scaffold(
      appBar: AppBar(
        title: Text("PageOne"),
      ),
      body: Container(
        child: GetBuilder<PageOneController>(
          builder: (controller) {
            return Text(
              "Two 界面点击了${oneController.count}次",
              style: TextStyle(fontSize: 32, color: Colors.redAccent),
            );
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          oneController.goTwoPage();
        },
        child: Icon(Icons.arrow_forward_ios_outlined),
      ),
    );
  }
}

class PageOneController extends GetxController {
  var count = 0;

  incremnt() {
    count++;
    update();
  }

  goTwoPage() {
    Get.to(() => const PageTwo(), arguments: {"msg": "今天天气特别好"});
  }
}
